package com.example.administrator.baikangxing.activity;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.baikangxing.R;
import com.example.administrator.baikangxing.bean.SleepBean;
import com.example.administrator.baikangxing.config.Constants;
import com.example.administrator.baikangxing.utils.TimeUtils;
import com.example.administrator.baikangxing.view.SleepTimeView;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class SleepActivity extends BaseActivity implements View.OnClickListener {
    private LinearLayout sleep_ll_statistics;
    private List<SleepBean> list;
    private Random random;
    private SleepTimeView sleep_content;
    private TextView sleep_tv_sleep;
    private TextView sleep_tv_shallow;
    private TextView sleep_tv_deep;

    @Override
    public int getContentViewLayoutId() {
        return R.layout.activity_sleep;
    }

    @Override
    public void initView() {
        setTitles("睡眠");
        setRightIcon(R.drawable.right_share);
        sleep_ll_statistics = findView(R.id.sleep_ll_Statistics);
        sleep_content = findView(R.id.sleep_stv_content);
        sleep_tv_shallow = findView(R.id.sleep_tv_shallow);
        sleep_tv_sleep = findView(R.id.sleep_tv_sleep);
        sleep_tv_deep = findView(R.id.sleep_tv_deep);
        sleep_ll_statistics.setOnClickListener(this);
        base_ib_menu.setOnClickListener(this);
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {
        Intent intent = getIntent();
        String sleep = intent.getStringExtra(Constants.HEALTH_TARGET[5] + "sleep");
        String deep = intent.getStringExtra(Constants.HEALTH_TARGET[5] + "deep");
        int[] sleep_time = TimeUtils.minTohours(sleep);
        int[] deep_time = TimeUtils.minTohours(deep);
        int[] shallow_time = TimeUtils.minTohours(String.valueOf(Integer.valueOf(sleep) - Integer.valueOf(deep)));
        sleep_tv_sleep.setText(sleep_time[0]+"时"+sleep_time[1]+"分");
        sleep_tv_deep.setText(deep_time[0]+"时"+deep_time[1]+"分");
        sleep_tv_shallow.setText(shallow_time[0]+"时"+shallow_time[1]+"分");
        list = new ArrayList<>();
        random = new Random();
        float total = 7;
        float f = 0;
        for (int i = 0; i < 10; i++) {
            int ran = random.nextInt(3);
            if (f <= total) {
                f += 0.6 * ran + 0.2;
                SleepBean sb = new SleepBean();
                sb.setSleepTime(f);
                sb.setSleepType(ran);
                list.add(sb);
            } else {
                break;
            }
        }
        sleep_content.setResources(list,f);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.sleep_ll_Statistics:
                Intent intent = new Intent(this, StatisticsSleepActivity.class);
                startActivity(intent);
                break;
            case R.id.base_ib_menu:
                Intent intent1 = new Intent(this, ShareSleepActivity.class);
                startActivity(intent1);
                break;
        }
    }
}
